// 导入包
import Vue from 'vue'
import VueRouter from 'vue-router'
import cookie from 'js-cookie'
// 导入路由
import MovieRoute from '@/routers/Movie'
import CinemaRoute from '@/routers/Cinema'
import MineRoute from '@/routers/Mine'
Vue.use(VueRouter)
// export default new VueRouter({
//     mode:'history',
//     routes:[
//         MovieRoute,
//         CinemaRoute,
//         MineRoute,
//         {
//             path:'/*',
//             redirect:'/movie/'
//         }
//     ]
// })

const router = new VueRouter({
    mode:'history',
    routes:[
        MovieRoute,
        CinemaRoute,
        MineRoute,
        {
            path:'/*',
            redirect:'/movie/'
        }
    ]
})
// 全局路由守卫
router.beforeEach(function(to,from,next){
    // to,from都是路由对象
    let path = to.path;
    if(path=='/mine/login'){
        next()
    }else{
        let isLogin = cookie.get().useInfo;
        if(isLogin){
            next()
        }else{
            next('/mine/login')
        }
    }
})

export default router;